package cn.silver.module.quartz.controller;

import cn.silver.framework.core.model.DictModel;
import cn.silver.framework.openapi.model.Result;
import cn.silver.framework.web.controller.ApiController;
import cn.silver.module.quartz.constant.QuartzGroupConstant;
import cn.silver.module.quartz.constant.QuartzResultConstant;
import cn.silver.module.quartz.constant.QuartzStatusConstant;
import cn.silver.module.quartz.constant.QuartzStrategyConstant;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

import static cn.silver.framework.core.constant.CacheConstants.MODEL_MAP;


/**
 * @author zhouxiaobo
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/quartz")
@Tag(name = "Api接口-定时任务管理")
public class SysQuartzApiController extends ApiController {
    static {
        MODEL_MAP.put("system-quartz-group", QuartzGroupConstant.getModels());
        MODEL_MAP.put("system-quartz-status", QuartzStatusConstant.getModels());
        MODEL_MAP.put("system-quartz-result", QuartzResultConstant.getModels());
        MODEL_MAP.put("system-quartz-strategy", QuartzStrategyConstant.getModels());
    }

    @GetMapping("/static/{code}")
    @Operation(summary = "查询枚举数据", description = "根据枚举编码查询枚举数据")
    public Result<List<DictModel>> getStaticData(@Parameter(name = "code", description = "枚举编码", required = true) @PathVariable String code) {
        return Result.ok(MODEL_MAP.getOrDefault(code, Collections.emptyList()));
    }

}
